package work;

/**
 * @TODO
 * @Author xu
 * 2025/2/24
 */
import java.util.ArrayList;
public class Day3_10 {
    public static void main(String[] args) {
        int limit = 50000;
        ArrayList<Integer> perfectNumbers = new ArrayList<>();
        for (int p = 2; p < 16; p++) {
            int mersenPrime = (1 << p) - 1;
            if (isPrime(mersenPrime)) {
                int perfectNumber = (1 << (p - 1)) * mersenPrime;
                if (perfectNumber <= limit) {
                    perfectNumbers.add(perfectNumber);
                }
            }
        }

        System.out.println("50000以内的完备数有：");
        for (int num : perfectNumbers) {
            System.out.println(num);
        }
    }

    private static boolean isPrime(int num) {
        if (num <= 1) return false;
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) return false;
        }
        return true;
    }



}
